package HTTPRecieveParser;

import HTTPSendIntegrator.MmsMessageException;

public class NotifyResp {
	
	private String notifyRespMessage;
	
	public static final String MMS_MESSAGE_TYPE = "X-Mms-Message-Type:";
	public static final String MMS_TRANSACTION_ID = "X-Mms-Transaction-ID:";
	public static final String MMS_VERSION = "X-Mms-MMS-Version:";
	public static final String MMS_STATUS = "X-Mms-Status:";
	public static final String MMS_REPORT_ALLOWED = "X-Mms-Report-Allowed:";
	
	private String mmsMessageType;
	private String mmsTransactionId;
	private String mmsVersion;
	private String mmsStatus;
	private String mmsReportAllowed;

	public String getMessageType(){
		return mmsMessageType;
	}
	
	public String getTransactionId(){
		return mmsTransactionId;
	}
	
	public String getVersion(){
		return mmsVersion;
	}

	public String getStatus(){
		return mmsStatus;
	}

	public String getReportAllowed(){
		return mmsReportAllowed;
	}

	public NotifyResp(String notifyRespMessage){
		this.notifyRespMessage = notifyRespMessage;
	}
	
	public void decodeMessage() throws MmsMessageException {
	
		try{
			String[] result = notifyRespMessage.split("\n");
			for(int i=0; i<result.length; i++)
			{
					if(result[i].startsWith(MMS_MESSAGE_TYPE))
						mmsMessageType=(result[i].substring((result[i].indexOf(':'))+2));
					
					if(result[i].startsWith(MMS_TRANSACTION_ID))
						mmsTransactionId=result[i].substring((result[i].indexOf(':'))+2); 
					
					if(result[i].startsWith(MMS_VERSION))
						mmsVersion=result[i].substring((result[i].indexOf(':'))+2);
					
					if(result[i].startsWith(MMS_REPORT_ALLOWED))
						mmsReportAllowed=result[i].substring((result[i].indexOf(':'))+2);
					
					if(result[i].startsWith(MMS_STATUS))
						mmsStatus=result[i].substring((result[i].indexOf(':'))+2);			
			}
			
		}catch (ArrayIndexOutOfBoundsException e){
			System.out.println("Malformed response message");
		}
	}
}
